import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { Goods } from './goods.entity';

@Entity()
export class Category {
  @ApiProperty({ description: '分类ID', example: 1 })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '分类名称', example: '电子产品' })
  @Column({ length: 50 })
  name: string;

  @ApiProperty({ description: '分类描述', example: '包含手机、电脑等电子设备' })
  @Column({ type: 'text', nullable: true })
  description: string;

  @ApiProperty({ description: '分类图标', example: 'electronics.png' })
  @Column({ length: 200, nullable: true })
  icon: string;

  @ApiProperty({ description: '排序', example: 1 })
  @Column({ type: 'int', default: 0 })
  sort: number;

  @ApiProperty({ description: '该分类下的商品', type: () => [Goods] })
  @OneToMany(() => Goods, (goods) => goods.category)
  goods: Goods[];

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn()
  createTime: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn()
  updateTime: Date;
}
